import LevelInitBase from "../LevelCommon/LevelInitBase";
import LevelControl10 from "../LevelControl/LevelControl10";
import RoomControl from "../LevelCommon/RoomControl";
import { utils } from "../../utils/CommonUtil";
import FocusMoreParentObj from "../Prefabs/InteractivObj/Common/FocusMoreParentObj";
import PhysPassLock from "../Prefabs/InteractivObj/PhysPassLock/PhysPassLock";
import PhysPassKey from "../Prefabs/InteractivObj/PhysPassLock/PhysPassKey";
import Gate from "../Prefabs/InteractivObj/Gate";
import EnumData from "../../Enum/EnumData";
import CallToLevel from "../Prefabs/CallToLevel";
import RotateObj from "../Prefabs/InteractivObj/Common/RotateObj";
import PasswordLock from "../Prefabs/InteractivObj/Password/PasswordLock";
import PasswordKey from "../Prefabs/InteractivObj/Password/PasswordKey";
import MoveObj from "../Prefabs/InteractivObj/Common/MoveObj";
import GamePropObj from "../Prefabs/InteractivObj/Common/GamePropObj";
import FluorescentObj from "../Prefabs/InteractivObj/FluorescentObj/FluorescentObj";
import FocusParentObj from "../Prefabs/InteractivObj/Common/FocusParentObj";
import ArrowLock from "../Prefabs/InteractivObj/ArrowLock/ArrowLock";
import ArrowLockKey from "../Prefabs/InteractivObj/ArrowLock/ArrowLockKey";
import GamePropConst from "../../constant/GamePropConst";
import RotateCommon from "../Prefabs/InteractivObj/Common/RotateCommon";

export default class LevelInit10 extends LevelInitBase {
    private room1: Laya.Sprite3D;

    private container: Laya.Sprite3D;

    public startInitDetail() {
        this.levelRoot.addComponent(LevelControl10);
        this.room1 = this.LevelObjs.getChildByName("room1") as Laya.Sprite3D;
        this.room1.addComponent(RoomControl);
        this.container = this.room1.getChildByName("Container") as Laya.Sprite3D;

        let physLock_focus = this.room1.getChildByName("physLock_focus");
        utils.CommonUtils.CustomAddComponent(physLock_focus, FocusMoreParentObj);

        let physLock = physLock_focus.getChildByName("physLock");
        let PhysPassLock_physLock = utils.CommonUtils.CustomAddComponent(physLock, PhysPassLock) as PhysPassLock;
        PhysPassLock_physLock.isDestroyEnd = true;
        PhysPassLock_physLock.correctPassInde.push(1);
        PhysPassLock_physLock.correctPassInde.push(10);
        PhysPassLock_physLock.correctPassInde.push(11);
        PhysPassLock_physLock.correctPassInde.push(11);

        for (let index = 0; index < physLock.numChildren; index++) {
            let child = physLock.getChildAt(index).getChildAt(0);
            let physKey = utils.CommonUtils.CustomAddComponent(child, PhysPassKey) as PhysPassKey;
            physKey.rotateAngle = -30;
        }

        let walls = this.room1.getChildByName("walls");
        let wall1 = walls.getChildByName("wall1");
        let wall2 = walls.getChildByName("wall2");
        let wall3 = walls.getChildByName("wall3");
        let wall4 = walls.getChildByName("wall4");

        //#region wall1

        let endGate = wall1.getChildByName("endGate");
        let Gate_endGate = utils.CommonUtils.CustomAddComponent(endGate, Gate) as Gate;
        Gate_endGate.needPropId = 1111;
        Gate_endGate.Angle = -30;
        Gate_endGate.Axis = EnumData.Axis.Y;

        let gateLockFocus = wall1.getChildByName("gateLockFocus");
        let FocusParentObj_gateLockFocus = utils.CommonUtils.CustomAddComponent(gateLockFocus, FocusParentObj) as FocusParentObj;

        let handLock = gateLockFocus.getChildByName("handLock");
        utils.CommonUtils.CustomAddComponent(handLock, CallToLevel);

        let passWordLock = gateLockFocus.getChildByName("passWordLock");
        let RotateObj_passWordLock = utils.CommonUtils.CustomAddComponent(passWordLock, RotateObj) as RotateObj;
        RotateObj_passWordLock.IsRotateOnce = true;
        RotateObj_passWordLock.targetRotate = new Laya.Vector3(0, -90, 0);

        let PasswordLock_passWordLock = utils.CommonUtils.CustomAddComponent(passWordLock, PasswordLock) as PasswordLock;
        PasswordLock_passWordLock.passWord = "1859";

        let keyBoard = passWordLock.getChildByName("keyBoard") as Laya.Sprite3D;
        for (let index = 0; index < keyBoard.numChildren; index++) {
            let child = keyBoard.getChildAt(index);
            let passwordKey = utils.CommonUtils.CustomAddComponent(child, PasswordKey) as PasswordKey;
            if (child.name == "Box045") {
                passwordKey.keyValue = "enter"
            } else if (child.name == "Box044") {
                passwordKey.keyValue = "0"
            }
            else {
                passwordKey.keyValue = (index + 1) + "";
            }
        }

        let Box034 = passWordLock.getChildByName("Box034");
        utils.CommonUtils.CustomAddComponent(Box034, CallToLevel);
        //#endregion

        //#region wall2
        let GameObjectParent = wall2.getChildByName("wall2").getChildByName("GameObject");
        let GameObject = GameObjectParent.getChildByName("GameObject");
        utils.CommonUtils.CustomAddComponent(GameObject, FocusParentObj);

        let Object011 = GameObject.getChildByName("Object011");
        let MoveObj_Object011 = utils.CommonUtils.CustomAddComponent(Object011, MoveObj) as MoveObj;
        MoveObj_Object011.VoiceName = "move";
        MoveObj_Object011.targetPos = new Laya.Vector3(9.05, 2.153, 7.67);

        let tomatoBox = GameObjectParent.getChildByName("tomatoBox");
        utils.CommonUtils.CustomAddComponent(tomatoBox, FocusParentObj);

        let tomato_mima = tomatoBox.getChildByName("r10_tomato_mima");
        let Fluorescent_tomato_mima = utils.CommonUtils.CustomAddComponent(tomato_mima, FluorescentObj) as FluorescentObj;
        Fluorescent_tomato_mima.needPropId = 51;
        Fluorescent_tomato_mima.isShouldUse = true;

        let model = GameObjectParent.getChildByName("model");
        utils.CommonUtils.CustomAddComponent(model, FocusParentObj);

        let fireBird = model.getChildByName("fireBird");
        utils.CommonUtils.CustomAddComponent(fireBird, CallToLevel);

        let SM_Item_Alcohol_03 = GameObjectParent.getChildByName("SM_Item_Alcohol_03");
        let GamePropObj_SM_Item_Alcohol_03 = utils.CommonUtils.CustomAddComponent(SM_Item_Alcohol_03, GamePropObj) as GamePropObj;
        GamePropObj_SM_Item_Alcohol_03.gamePropId = 51;

        let Plane001 = wall2.getChildByName("Plane001");
        utils.CommonUtils.CustomAddComponent(Plane001, FocusMoreParentObj);

        let jinianpin = wall2.getChildByName("jinianpin");
        let GamePropObj_jinianpin = utils.CommonUtils.CustomAddComponent(jinianpin, GamePropObj) as GamePropObj;
        GamePropObj_jinianpin.gamePropId = 11;
        //#endregion

        //#region wall3
        let SM_Prop_Bookshelf_02 = wall3.getChildByName("SM_Prop_Bookshelf_02");
        let SM_Bld_House_RanchSlider_01 = SM_Prop_Bookshelf_02.getChildByName("SM_Bld_House_RanchSlider_01");
        let focus = SM_Bld_House_RanchSlider_01.getChildByName("focus");
        utils.CommonUtils.CustomAddComponent(focus, FocusParentObj);

        let fridgeGate1 = focus.getChildByName("fridgeGate1");
        let MoveObj_fridgeGate1 = utils.CommonUtils.CustomAddComponent(fridgeGate1, MoveObj) as MoveObj;
        MoveObj_fridgeGate1.VoiceName = "move";
        MoveObj_fridgeGate1.targetPos = new Laya.Vector3(-1.69, 3.64, -0.1);
        let SM_Bld_House_RanchSlider_Glass = fridgeGate1.getChildByName("SM_Bld_House_RanchSlider_Glass");
        utils.CommonUtils.CustomAddComponent(SM_Bld_House_RanchSlider_Glass, CallToLevel);

        let fridgeGate2 = focus.getChildByName("fridgeGate2");
        let MoveObj_fridgeGate2 = utils.CommonUtils.CustomAddComponent(fridgeGate2, MoveObj) as MoveObj;
        MoveObj_fridgeGate2.VoiceName = "move";
        MoveObj_fridgeGate2.targetPos = new Laya.Vector3(-0.1800007, 3.64, 0.14);
        let SM_Bld_House_RanchSlider_Door_Glass = fridgeGate2.getChildByName("SM_Bld_House_RanchSlider_Door_Glass");
        utils.CommonUtils.CustomAddComponent(SM_Bld_House_RanchSlider_Door_Glass, CallToLevel);

        let hold_lianzi = focus.getChildByName("hold_lianzi");
        utils.CommonUtils.CustomAddComponent(hold_lianzi, CallToLevel);

        let hand_hold = focus.getChildByName("hand_hold");
        let GamePropObj_hand_hold = utils.CommonUtils.CustomAddComponent(hand_hold, GamePropObj) as GamePropObj;
        GamePropObj_hand_hold.isNeedCallToLevel = true;
        GamePropObj_hand_hold.gamePropId = 52;

        let SM_Item_Drink_Glass_02 = SM_Bld_House_RanchSlider_01.getChildByName("SM_Item_Drink_Glass_02");

        let GamePropObj_SM_Item_Drink_Glass_02 = utils.CommonUtils.CustomAddComponent(SM_Item_Drink_Glass_02, GamePropObj) as GamePropObj;
        GamePropObj_SM_Item_Drink_Glass_02.gamePropId = 53;

        let arrowLock1 = SM_Prop_Bookshelf_02.getChildByName("arrowLock1");
        utils.CommonUtils.CustomAddComponent(arrowLock1, FocusParentObj);

        let ArrowLock_arrowLock1 = utils.CommonUtils.CustomAddComponent(arrowLock1, ArrowLock) as ArrowLock;
        ArrowLock_arrowLock1.correctDirs.push(EnumData.ArrowDirEnum.bottom);
        ArrowLock_arrowLock1.correctDirs.push(EnumData.ArrowDirEnum.left);
        ArrowLock_arrowLock1.correctDirs.push(EnumData.ArrowDirEnum.left);
        ArrowLock_arrowLock1.correctDirs.push(EnumData.ArrowDirEnum.right);
        ArrowLock_arrowLock1.correctDirs.push(EnumData.ArrowDirEnum.up);
        ArrowLock_arrowLock1.correctDirs.push(EnumData.ArrowDirEnum.bottom);

        for (let index = 0; index < 5; index++) {
            let child = arrowLock1.getChildAt(index);
            if (index == 0) {
                utils.CommonUtils.CustomAddComponent(child, CallToLevel);
            } else {
                let ArrowLockKey_child = utils.CommonUtils.CustomAddComponent(child, ArrowLockKey) as ArrowLockKey;
                switch (index) {
                    case 1:
                        ArrowLockKey_child.curDir = EnumData.ArrowDirEnum.right;
                        break;
                    case 2:
                        ArrowLockKey_child.curDir = EnumData.ArrowDirEnum.left;
                        break;
                    case 3:
                        ArrowLockKey_child.curDir = EnumData.ArrowDirEnum.up;
                        break;
                    case 4:
                        ArrowLockKey_child.curDir = EnumData.ArrowDirEnum.bottom;
                        break;

                    default:
                        break;
                }
            }
        }

        let arrowLock2 = SM_Prop_Bookshelf_02.getChildByName("arrowLock2");
        utils.CommonUtils.CustomAddComponent(arrowLock2, FocusParentObj);
        let ArrowLock_arrowLock2 = utils.CommonUtils.CustomAddComponent(arrowLock2, ArrowLock) as ArrowLock;
        ArrowLock_arrowLock2.correctDirs.push(EnumData.ArrowDirEnum.bottom);
        ArrowLock_arrowLock2.correctDirs.push(EnumData.ArrowDirEnum.up);
        ArrowLock_arrowLock2.correctDirs.push(EnumData.ArrowDirEnum.right);
        ArrowLock_arrowLock2.correctDirs.push(EnumData.ArrowDirEnum.left);
        ArrowLock_arrowLock2.correctDirs.push(EnumData.ArrowDirEnum.left);
        ArrowLock_arrowLock2.correctDirs.push(EnumData.ArrowDirEnum.bottom);

        for (let index = 0; index < 5; index++) {
            let child = arrowLock2.getChildAt(index);
            if (index == 0) {
                utils.CommonUtils.CustomAddComponent(child, CallToLevel);
            } else {
                let ArrowLockKey_child = utils.CommonUtils.CustomAddComponent(child, ArrowLockKey) as ArrowLockKey;
                switch (index) {
                    case 1:
                        ArrowLockKey_child.curDir = EnumData.ArrowDirEnum.right;
                        break;
                    case 2:
                        ArrowLockKey_child.curDir = EnumData.ArrowDirEnum.left;
                        break;
                    case 3:
                        ArrowLockKey_child.curDir = EnumData.ArrowDirEnum.up;
                        break;
                    case 4:
                        ArrowLockKey_child.curDir = EnumData.ArrowDirEnum.bottom;
                        break;

                    default:
                        break;
                }
            }
        }

        let SM_Item_Pizza_Box_01 = SM_Prop_Bookshelf_02.getChildByName("SM_Item_Pizza_Box_01");
        let GamePropObj_SM_Item_Pizza_Box_01 = utils.CommonUtils.CustomAddComponent(SM_Item_Pizza_Box_01,GamePropObj) as GamePropObj;
        GamePropObj_SM_Item_Pizza_Box_01.gamePropId = 59;

        let SM_Prop_Crate_Wall_01 = wall3.getChildByName("SM_Prop_Crate_Wall_01");
        utils.CommonUtils.CustomAddComponent(SM_Prop_Crate_Wall_01,FocusParentObj);

        let Object006 =  SM_Prop_Crate_Wall_01.getChildByName("Object006");
        let GamePropObj_Object006 = utils.CommonUtils.CustomAddComponent(Object006,GamePropObj) as GamePropObj;
        GamePropObj_Object006.gamePropId = 54;

        let jinianpin1 = wall3.getChildByName("jinianpin");
        let GamePropObj_jinianpin1 = utils.CommonUtils.CustomAddComponent(jinianpin1,GamePropObj) as GamePropObj;
        GamePropObj_jinianpin1.gamePropId = 11;

        //#endregion

        //#region wall4
        let ChamferBox001 = wall4.getChildByName("ChamferBox001");
        utils.CommonUtils.CustomAddComponent(ChamferBox001,FocusParentObj);

        let Object004 =ChamferBox001.getChildByName("Object004");
        let RotateObj_Object004 = utils.CommonUtils.CustomAddComponent(Object004,RotateObj)as RotateObj;
        RotateObj_Object004.IsRotateOnce = true;
        RotateObj_Object004.VoiceName ="openGate";
        RotateObj_Object004.targetRotate = new Laya.Vector3(0,0,90);
        
        let Object005 =ChamferBox001.getChildByName("Object005");
        let RotateObj_Object005 = utils.CommonUtils.CustomAddComponent(Object005,RotateObj)as RotateObj;
        RotateObj_Object005.IsRotateOnce = true;
        RotateObj_Object005.VoiceName ="openGate";
        RotateObj_Object005.targetRotate = new Laya.Vector3(0,-180,90);
        
        let SM_Item_Shop_Goods_05 = ChamferBox001.getChildByName("SM_Item_Shop_Goods_05");
        let GamePropObj_SM_Item_Shop_Goods_05 = utils.CommonUtils.CustomAddComponent(SM_Item_Shop_Goods_05,GamePropObj) as GamePropObj;
        GamePropObj_SM_Item_Shop_Goods_05.gamePropId = 55;

        let handFocus = ChamferBox001.getChildByName("handFocus");
        utils.CommonUtils.CustomAddComponent(handFocus,FocusParentObj);

        let openHand = handFocus.getChildByName("openHand");
        let RotateObj_openHand = utils.CommonUtils.CustomAddComponent(openHand,RotateObj) as RotateObj;
        RotateObj_openHand.IsRotateOnce = true;
        RotateObj_openHand.targetRotate =new Laya.Vector3(0,180,0);

        let openHand_focus = openHand.getChildByName("openHand_focus");
        utils.CommonUtils.CustomAddComponent(openHand_focus,CallToLevel);

        let openLianZi =  handFocus.getChildByName("openLianZi");
        utils.CommonUtils.CustomAddComponent(openLianZi,CallToLevel);

        let focus_wall4 = wall4.getChildByName("focus");
        utils.CommonUtils.CustomAddComponent(focus_wall4,FocusParentObj);

        let weiboBox =  focus_wall4.getChildByName("weiboBox");
        utils.CommonUtils.CustomAddComponent(weiboBox,CallToLevel);

        let gate =  weiboBox.getChildByName("gate");
        let RotateObj_gate = utils.CommonUtils.CustomAddComponent(gate,RotateObj)as RotateObj;
        RotateObj_gate.IsRotateOnce = true;
        RotateObj_gate.targetRotate = new Laya.Vector3(0,-90,0);

        let redKey_prop = weiboBox.getChildByName("redKey_prop");
        let GamePropObj_redKey_prop = utils.CommonUtils.CustomAddComponent(redKey_prop,GamePropObj) as GamePropObj;
        GamePropObj_redKey_prop.gamePropId = 16;

        let controller = focus_wall4.getChildByName("controller");
        let RotateCommon_controller = utils.CommonUtils.CustomAddComponent(controller,RotateCommon) as RotateCommon;
        RotateCommon_controller.rotateAngle = -60;
        RotateCommon_controller.voiceName = "physPassLock";

        let weibolu = focus_wall4.getChildByName("weibolu");
        utils.CommonUtils.CustomAddComponent(weibolu,CallToLevel);

        let hotPiza = focus_wall4.getChildByName("hotPiza");
        hotPiza.active = false;

        let GamePropObj_hotPiza = utils.CommonUtils.CustomAddComponent(hotPiza,GamePropObj) as GamePropObj;
        GamePropObj_hotPiza.gamePropId = 62;
        console.log(hotPiza.getChildAt(1).name);
        let SM_Item_Pizza_01 = hotPiza.getChildByName("SM_Item_Pizza_mima");
        let FluorescentObj_SM_Item_Pizza_01 = utils.CommonUtils.CustomAddComponent(SM_Item_Pizza_01,FluorescentObj)as FluorescentObj;
        FluorescentObj_SM_Item_Pizza_01.needPropId = 111111;
        FluorescentObj_SM_Item_Pizza_01.isShowStart = true;

        let jinianpin2 =  wall4.getChildByName("jinianpin");
        let GamePropObj_jinianpin2 = utils.CommonUtils.CustomAddComponent(jinianpin2,GamePropObj) as GamePropObj;
        GamePropObj_jinianpin2.gamePropId = 11;
        //#endregion

    }
}